package cn.lxh.remote.fallback;

import cn.lxh.remote.api.RuleFeignApi;
import cn.lxh.remote.pojo.bo.CalculateMileageFeeBo;
import cn.lxh.remote.pojo.bo.DivideAccountsBo;
import cn.lxh.remote.pojo.result.DivideAccountsResult;
import cn.lxh.remote.pojo.result.WaitFeeResult;
import cn.lxh.result.JSONResult;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author lxh Create Time: 2023/12/23 17:05
 * LoginFeignApiFallbackFactory熔断降级处理方案类
 */
@Component
public class RuleFeignApiFallbackFactory implements FallbackFactory<RuleFeignApi> {
    @Override
    public RuleFeignApi create(Throwable cause) {
        return new RuleFeignApi() {
            @Override
            public JSONResult calculateMileageFee(CalculateMileageFeeBo calculateMileageFeeBo) {
                cause.printStackTrace();
                return JSONResult.error("里程费计价调用失败");
            }

            @Override
            public JSONResult<WaitFeeResult> calculateWaitFee(Integer waitMinute) {
                cause.printStackTrace();
                return JSONResult.error("等时费计价调用失败");
            }

            @Override
            public JSONResult<DivideAccountsResult> calculateSplitAccounts(DivideAccountsBo divideAccountsBo) {
                cause.printStackTrace();
                return JSONResult.error("分账调用失败");
            }
        };
    }
}
